using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace WebDauGia.Domain.Models.Mapping
{
    public class DanhSachDauGiaMap : EntityTypeConfiguration<DanhSachDauGia>
    {
        public DanhSachDauGiaMap()
        {
            // Primary Key
            this.HasKey(t => new { t.id, t.idsanpham, t.tgdatgia, t.datgia, t.idkhachhang });

            // Properties
            this.Property(t => t.id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(t => t.idsanpham)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.idkhachhang)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            // Table & Column Mappings
            this.ToTable("DanhSachDauGia");
            this.Property(t => t.id).HasColumnName("id");
            this.Property(t => t.idsanpham).HasColumnName("idsanpham");
            this.Property(t => t.tgdatgia).HasColumnName("tgdatgia");
            this.Property(t => t.datgia).HasColumnName("datgia");
            this.Property(t => t.idkhachhang).HasColumnName("idkhachhang");

            // Relationships
            this.HasRequired(t => t.KhachHang)
                .WithMany(t => t.DanhSachDauGias)
                .HasForeignKey(d => d.idkhachhang);
            this.HasRequired(t => t.SanPham)
                .WithMany(t => t.DanhSachDauGias)
                .HasForeignKey(d => d.idsanpham);
            this.HasRequired(t => t.SanPham1)
                .WithMany(t => t.DanhSachDauGias1)
                .HasForeignKey(d => d.idsanpham);

        }
    }
}
